<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8" />
    <title>添加联系人</title>

    <%-- <link href="static/css/bootstrap.min.css" rel="stylesheet" />--%>
    <link href="static/mycss/bootstrap.min.css" rel="stylesheet" />
    <script src='static/js/jquery-1.9.1.min.js'></script>
     <!-- <script src='static/js/jquery-3.2.1.min.js'></script> -->
     <script type="text/javascript" src="plugins/jquery-validation/jquery.validate.js"></script>
     <!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
    <script type="text/javascript" src="static/js/layer.js"></script>
    <link rel="stylesheet" href="static/css/layui.css" media="all">
    <script type="text/javascript">
    $(document).ready(function(){
        $("#contStatus").val("${userObj.contStatus}")
    	$("#contMobile1").blur(function(){
    		var contMobile1 = $("#contMobile1").val();
            console.log(contMobile1);
            if(!contMobile1=="") {
                var reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
                var result = reg.test(contMobile1);
                console.log("result:" + result);
                if (result) {
                    return true;
                } else {
                    $("#contMobile1").val("");
                    layer.alert('请输入正确手机号', {
                        skin: 'layui-layer-molv' //样式类名
                        , closeBtn: 0
                    });
                }
            }

    	});
    	$("#contMobile2").blur(function(){
    		var contMobile2 = $("#contMobile2").val();
            console.log(contMobile2);
            if(!contMobile2=="") {
                var reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
                var result = reg.test(contMobile2);
                console.log("result:" + result);
                if (result) {
                    return true;
                } else {
                    $("#contMobile2").val("");
                    layer.alert('请输入正确手机号', {
                        skin: 'layui-layer-molv' //样式类名
                        , closeBtn: 0
                    });
                }
            }
    	});
    	$("#contMobile3").blur(function(){
    		var contMobile3 = $("#contMobile3").val();
            console.log(contMobile3);
            if(!contMobile3=="") {
                var reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
                console.log();
                var result = reg.test(contMobile3);
                console.log("result:" + result);
                if (result) {
                    return true;
                } else {
                    $("#contMobile3").val("");
                    layer.alert('请输入正确手机号', {
                        skin: 'layui-layer-molv' //样式类名
                        , closeBtn: 0
                    });
                }
            }
    	});
    	$("#eMail").blur(function(){
    		var eMail = $("#eMail").val();
            console.log(eMail);
            if(!eMail=="") {
                var reg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
                var result = reg.test(eMail);
                console.log("result:" + result);
                if (result) {
                    return true;
                } else {
                    $("#eMail").val("");
                    layer.alert('请输入正确邮箱', {
                        skin: 'layui-layer-molv' //样式类名
                        , closeBtn: 0
                    });
                }
            }

    	});
    })	
    
        $(top.hangge());
         function contactAdd(){
          var issubmit = true;
       	  if($("#contUserName").val()==""){
       			$("#contUserName").tips({
       				side:3,
       		        msg:'请输入联系人姓名',
       		        bg:'#AE81FF',
       		        time:2
       		    });
       			issubmit = false;
       		} 
       	    if($("#contMobile1").val()==""){
       			$("#contMobile1").tips({
       				side:3,
       		        msg:'请输入手机号码',
       		        bg:'#AE81FF',
       		        time:2
       		    });
       			issubmit = false;
       		} 
       	    if($("#contType").val()=="0"){
       			$("#contType").tips({
       				side:3,
       		        msg:'请选择联系人类别',
       		        bg:'#AE81FF',
       		        time:2
       		    });
       			issubmit = false;
       		}
	       	 if(issubmit==true){
	 	    	console.log("提交")
	 	     $("#commentForm").submit();
	 	    }
        }
    </script>
    <script type="text/javascript">
    $(function(){
 		var code = "${code}";
 		var msg = "${msg}";
 		if(code){
	    	alert(msg);
 		}
 	});
    function clsIDCard(CardNo) {
        this.Valid=false;
        this.ID15='';
        this.ID18='';
        this.Local='';
        if(CardNo!=null)this.SetCardNo(CardNo);
    }

    // 设置身份证号码，15位或者18位
    clsIDCard.prototype.SetCardNo = function(CardNo) {
        this.ID15='';
        this.ID18='';
        this.Local='';
        CardNo=CardNo.replace(" ","");
        var strCardNo;
        if(CardNo.length==18) {
            pattern= /^\d{17}(\d|x|X)$/;
            if (pattern.exec(CardNo)==null)return;
            strCardNo=CardNo.toUpperCase();
        } else {
            pattern= /^\d{15}$/;
            if (pattern.exec(CardNo)==null)return;
            strCardNo=CardNo.substr(0,6)+'19'+CardNo.substr(6,9)
            strCardNo+=this.GetVCode(strCardNo);
        }
        this.Valid=this.CheckValid(strCardNo);
    }

    // 校验身份证有效性
    clsIDCard.prototype.IsValid = function() {
        return this.Valid;
    }

    // 返回生日字符串，格式如下，1981-10-10
    clsIDCard.prototype.GetBirthDate = function() {
        var BirthDate='';
        if(this.Valid)BirthDate=this.GetBirthYear()+'-'+this.GetBirthMonth()+'-'+this.GetBirthDay();
        return BirthDate;
    }

    // 返回生日中的年，格式如下，1981
    clsIDCard.prototype.GetBirthYear = function() {
        var BirthYear='';
        if(this.Valid)BirthYear=this.ID18.substr(6,4);
        return BirthYear;
    }

    // 返回生日中的月，格式如下，10
    clsIDCard.prototype.GetBirthMonth = function() {
        var BirthMonth='';
        if(this.Valid)BirthMonth=this.ID18.substr(10,2);
        if(BirthMonth.charAt(0)=='0')BirthMonth=BirthMonth.charAt(1);
        return BirthMonth;
    }

    // 返回生日中的日，格式如下，10
    clsIDCard.prototype.GetBirthDay = function() {
        var BirthDay='';
        if(this.Valid)BirthDay=this.ID18.substr(12,2);
        return BirthDay;
    }

    // 返回性别，1：男，0：女
    clsIDCard.prototype.GetSex = function() {
        var Sex='';
        if(this.Valid)Sex=this.ID18.charAt(16)%2;
        return Sex;
    }

    // 返回15位身份证号码
    clsIDCard.prototype.Get15 = function() {
        var ID15='';
        if(this.Valid)ID15=this.ID15;
        return ID15;
    }

    // 返回18位身份证号码
    clsIDCard.prototype.Get18 = function() {
        var ID18='';
        if(this.Valid)ID18=this.ID18;
        return ID18;
    }

    // 返回所在省，例如：上海市、浙江省
    clsIDCard.prototype.GetLocal = function() {
        var Local='';
        if(this.Valid)Local=this.Local;
        return Local;
    }

    clsIDCard.prototype.GetVCode = function(CardNo17) {
        var Wi = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);
        var Ai = new Array('1','0','X','9','8','7','6','5','4','3','2');
        var cardNoSum = 0;
        for (var i=0; i<CardNo17.length; i++)cardNoSum+=CardNo17.charAt(i)*Wi[i];
        var seq = cardNoSum%11;
        return Ai[seq];
    }

    clsIDCard.prototype.CheckValid = function(CardNo18) {
        if(this.GetVCode(CardNo18.substr(0,17))!=CardNo18.charAt(17))return false;
        if(!this.IsDate(CardNo18.substr(6,8)))return false;
        var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"};
        if(aCity[parseInt(CardNo18.substr(0,2))]==null)return false;
        this.ID18=CardNo18;
        this.ID15=CardNo18.substr(0,6)+CardNo18.substr(8,9);
        this.Local=aCity[parseInt(CardNo18.substr(0,2))];
        return true;
    }

    clsIDCard.prototype.IsDate = function(strDate) {
        var r = strDate.match(/^(\d{1,4})(\d{1,2})(\d{1,2})$/);
        if(r==null)return false;
        var d= new Date(r[1], r[2]-1, r[3]);
        return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[2]&&d.getDate()==r[3]);
    }


    function valiIdCard(idCard){
        console.log(idCard)
        if(idCard.trim()==""){
            return true
        }
        var checkFlag = new clsIDCard(idCard);
        console.log("checkFlag:"+checkFlag)
        if (!checkFlag.IsValid()) {
            console.log("false")
            return false;
        }else{
            console.log("true")
            return true;
        }
    }
    </script>
</head>
<body>
<div class="col-sm-12">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <form name="commentForm" class="form-horizontal m-t" id="commentForm" novalidate="novalidate" method="post" action="cuijimanage/contactinfoadd.do">
               <input type="hidden" id="id" name="id" value="${userObj.id}">
               <input type="hidden" id="userId" name="userId" value="${userObj.userId}">
                <input type="hidden" id="contSource" name="contSource" value="${userObj.contSource}">
                <input type="hidden" id="oldId" name="oldId" value="${userObj.oldId}">
                <div class="form-group col-sm-12">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">  联系人类别:</label>
                        <div class="col-sm-8">
                            <select   class="form-control " name="contType" id="contType">
                                <option value="0" <c:if test="${userObj.contType == '0' }">selected</c:if>>联系人类别</option> 
                                <option value="1" <c:if test="${userObj.contType == '1' }">selected</c:if> >紧急联系人</option>
                                <option value="2" <c:if test="${userObj.contType == '2' }">selected</c:if> >直系亲属</option>
                                <option value="3" <c:if test="${userObj.contType == '3' }">selected</c:if> >其他</option>
                            </select>
                        </div>
                    </div>

                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">  公司电话:</label>
                        <div class="col-sm-8">
                            <input id="contTellCom" type="text" class="form-control"  placeholder="${userObj.contTellCom}"  value="${userObj.contTellCom}"
                                   ng-class="{'error':signUpForm.regionSeatNum.$invalid && signUpForm.regionSeatNum.$touched}"
                                   name="contTellCom" required="" aria-required="true" ng-model="info.regionSeatNum"
                                   maxlength ='12'/>
                        </div>
                    </div></div>
                <div class="form-group col-sm-12">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label"> 联系人姓名:</label>
                        <div class="col-sm-8">
                            <input id="contUserName" name="contUserName" type="text" class="form-control" placeholder="${userObj.contUserName}" value="${userObj.contUserName}"
                                   name="contUserName" ng-model="info.appointFee" maxlength ='20'/>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">  手机号码1:</label>
                        <div class="col-sm-8">
                            <input id="contMobile1" name="contMobile1" type="text" class="form-control" placeholder="${userObj.contMobile1}" value="${userObj.contMobile1}"
                                   ng-class="{'error':signUpForm.regionTempSeatNum.$invalid && signUpForm.regionTempSeatNum.$touched}"
                                   required="" aria-required="true" ng-model="info.regionTempSeatNum"
                                   onblur="if(isNaN(this.value)||eval(this.value)<=0){alert('请输入正确的电话号码格式!');this.value='';}" maxlength ='11'/>
                        </div>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">  联系人身份证:</label>
                        <div class="col-sm-8">
                            <input id="contIdCard" name="contIdCard" type="text" class="form-control" placeholder="${userObj.contIdCard}" value="${userObj.contIdCard}"
                                   ng-class="{'error':signUpForm.regionTempSeatNum.$invalid && signUpForm.regionTempSeatNum.$touched}"
                                   required="" aria-required="true" ng-model="info.regionTempSeatNum"
                                   onblur="if(!valiIdCard(this.value)){ layer.alert('请输入正确身份证号', {
                                    skin: 'layui-layer-molv' //样式类名
                                    ,closeBtn: 0
                                });this.value='';}"  maxlength ='25'/>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">  手机号码2:</label>
                        <div class="col-sm-8">
                            <input id="contMobile2" name="contMobile2" type="text" class="form-control" placeholder="${userObj.contMobile2}" value="${userObj.contMobile2}"
                                   ng-class="{'error':signUpForm.regionTempSeatNum.$invalid && signUpForm.regionTempSeatNum.$touched}"
                                   required="" aria-required="true" ng-model="info.regionTempSeatNum"
                                   onblur="if(isNaN(this.value)||eval(this.value)<=0){alert('请输入正确的电话号码格式!');this.value='';}" maxlength ='11'/>
                        </div>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                     <div class="col-sm-6">
                        <label class="col-sm-4 control-label"> 状态:</label>
                        <div class="col-sm-8">
                            <select   class="form-control" name="contStatus" id="contStatus">
                                <!-- <option >有效</option>
                                <option >无效</option> -->
                                <option value="1" <c:if test="${userObj.contStatus == '1' }">selected</c:if> >无效</option>
                                <option value="0" <c:if test="${userObj.contStatus == '0' }">selected</c:if> >有效</option>

                            </select>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">  手机号码3:</label>
                        <div class="col-sm-8">
                            <input id="contMobile3" name="contMobile3" type="text" class="form-control" placeholder="${userObj.contMobile3}" value="${userObj.contMobile3}"
                                   ng-class="{'error':signUpForm.regionTempSeatNum.$invalid && signUpForm.regionTempSeatNum.$touched}"
                                   required="" aria-required="true" ng-model="info.regionTempSeatNum"
                                   onblur="if(isNaN(this.value)||eval(this.value)<=0){alert('请输入正确的电话号码格式!');this.value='';}" maxlength ='11'/>
                        </div>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label"> 住宅电话:</label>
                        <div class="col-sm-8">
                            <input id="contTell" name="contTell" type="text" class="form-control" placeholder="${userObj.contTell}" value="${userObj.contTell}"
                                   ng-class="{'error':signUpForm.regionTempSeatNum.$invalid && signUpForm.regionTempSeatNum.$touched}"
                                   required="" aria-required="true" ng-model="info.regionTempSeatNum"
                                   maxlength ='12'/>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label"> 邮件地址:</label>
                        <div class="col-sm-8">
                            <input id="eMail" name="eMail" type="text" class="form-control" placeholder="${userObj.eMail}" value="${userObj.eMail}"
                                   ng-class="{'error':signUpForm.regionTempSeatNum.$invalid && signUpForm.regionTempSeatNum.$touched}"
                                   required="" aria-required="true" ng-model="info.regionTempSeatNum" maxlength ='50'/>
                        </div>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <label class="col-sm-2 control-label"> 单位名称:</label>
                    <div class="col-sm-10">
                        <input id="contNameCom" name="contNameCom" type="text" class="form-control" placeholder="${userObj.contNameCom}" value="${userObj.contNameCom}"
                                   ng-class="{'error':signUpForm.regionTempSeatNum.$invalid && signUpForm.regionTempSeatNum.$touched}"
                                   required="" aria-required="true" ng-model="info.regionTempSeatNum" maxlength ='50'/>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <label class="col-sm-2 control-label"> 户籍地址:</label>
                    <div class="col-sm-10">
                        <input id="contAddrHk" type="text" class="form-control" placeholder="${userObj.contAddrHk}" value="${userObj.contAddrHk}"
                               ng-class="{'error':signUpForm.appointFee.$invalid && signUpForm.appointFee.$touched}"
                               name="contAddrHk" ng-model="info.appointFee" maxlength ='50'>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <label class="col-sm-2 control-label"> 单位地址:</label>
                    <div class="col-sm-10">
                        <input id="contAddrCom" name="contAddrCom" type="text" class="form-control"  placeholder="${userObj.contAddrCom}" value="${userObj.contAddrCom}"
                               ng-class="{'error':signUpForm.appointFee.$invalid && signUpForm.appointFee.$touched}"
                               name="contAddrCom" ng-model="info.appointFee" maxlength ='50'/>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <label class="col-sm-2 control-label"> 居住地址:</label>
                    <div class="col-sm-10">
                        <input id="contAddr" name="contAddr" type="text" class="form-control" placeholder="${userObj.contAddr}" value="${userObj.contAddr}"
                               ng-class="{'error':signUpForm.appointFee.$invalid && signUpForm.appointFee.$touched}"
                               name="contAddr" ng-model="info.appointFee" maxlength ='50'/>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <label class="col-sm-2 control-label">备注:</label>
                    <div class="col-sm-10">
                                     <textarea rows="6"  class="form-control" name="remark"  value="" maxlength ='199'>${userObj.remark}</textarea>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <div align="center" class="col-sm-7" >
                        <input type="button" id="fghghf" style="width:90px" class="btn btn-primary" onclick="contactAdd();" value="确认添加"/> 
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
